package com.ruoyi.project.drug.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.drug.domain.DrugFactory;
import com.ruoyi.project.drug.service.IDrugFactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drug/factory")
public class DrugFactoryController extends BaseController {
    @Autowired
    private IDrugFactoryService drugFactoryService;

    /**
     * 查询【厂家信息】列表
     */
    //@PreAuthorize("@ss.hasPermi('system:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugFactory drugFactory)
    {
        startPage();
        List<DrugFactory> list = drugFactoryService.selectDrugFactoryList(drugFactory);
        return getDataTable(list);
    }


    /**
     * 获取【请填写功能名称】详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:factory:query')")
    @GetMapping(value = "/{factId}")
    public AjaxResult getInfo(@PathVariable("factId") Long factId)
    {
        return AjaxResult.success(drugFactoryService.selectDrugFactoryById(factId));
    }
    //新增厂家
    //@PreAuthorize("@ss.hasPermi('system:factory:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugFactory drugFactory)
    {
        return toAjax(drugFactoryService.insertDrugFactory(drugFactory));
    }
    //修改厂家
    //@PreAuthorize("@ss.hasPermi('system:factory:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugFactory drugFactory)
    {
        return toAjax(drugFactoryService.updateDrugFactory(drugFactory));
    }
    //删除厂家
    //@PreAuthorize("@ss.hasPermi('system:factory:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{factIds}")
    public AjaxResult remove(@PathVariable Long[] factIds)
    {
        return toAjax(drugFactoryService.deleteDrugFactoryByIds(factIds));
    }
}
